<?

/**
* Use $_SESSION["GDate"] if you are using custom date
* or just use the system date 
*
* $today_date = $_SESSION["GDate"];
* $today_date = date("d-m-Y");
*
*/
$today_date		  = date("d-m-Y");

$thisSequence   = "IMPORT_SEQ";
$jobIdTag       = "Y4";

$srcDbHdr      = "IMPORT_HDR";
$srcDbDtl      = "IMPORT_DTL";
$srcDbHdrLog   = "LOG_IMPORT_HDR";
$srcDbSequence = "MST_SEQUENCE";

$UID     = unserialize($_SESSION["serUID"]);

$userId  = $UID->getUID();

$Db = new oracleDb;
$Db->init($_SESSION["ORCL"], 
           $_SESSION["OPASS"],
           $_SESSION["SID"],
           _NO_COMMENT);

if($Db->connect()){
	
	$thisPeriode = &$_SESSION["sysPeriode"];
	
	/**
	* Fetch the sequence number
	* and below is the how to
	* 
	* 1. we fetch the current number
	* 2. we update the current number
	* 3. if the fetched number as condition is  
	*    valid then there is no interuption while
	*    updating
	*
	*/
	
	$seqEditStatus = false;
	
	while($seqEditStatus == false){
	  
  	$CFetchers->fetchCurSequence($Db,
                	               $thisSequence,
                	               $thisPeriode,
                	               $srcDbSequence,
                	               $srcJidIndex);
  	
  	$CHandlers->initCurSequence($Db,
                	              $thisSequence,
                	              $srcJidIndex,
                	              $thisPeriode,
                	              $srcDbSequence,
                	              $seqEditStatus);
  }
  
  /**
  * Extract the system period
  *
  */
  $tmpDate = explode("-", $thisPeriode);
  $wrkDate = $tmpDate[0]. /* This period month */
             "-".
             $tmpDate[1]; /* This period year */
  
  $jobId  = addDigit((string) $srcJidIndex). 
            $srcJidIndex. 
            "/" .
            $jobIdTag.
            "/" .
            $wrkDate;
  
  $hdrDate = "TO_DATE('".$_POST["trDateEnt"]."' , 'dd-mm-YYYY')";
    
    
  $CFetchers->fetchHdrNo($Db,
                         $_POST["trDateEnt"],
                         $srcDbHdr,
                         $hdrNo);
              
  /**
  * Insert Log
  *
  */
  $CHandlers->insToDbLog($Db,
                         $today_date,
                         $jobId,
                         $userId,
                         $_SERVER["REMOTE_ADDR"],
                         _ENTRY_MODE,
                         $srcDbHdrLog);
                                
	$Db->commit();
	
	if($Db->getStatus()){
	
	  $Misc->usrMsg("Upload Complete");
	}else{
	  
	  $Misc->usrDieJs("Upload Process Interupted");
	}
	
	$Db->dc();
	
	/**
	* Pending...
	* I'm not sure if this 
	* reset procedure off
	* causes buggy 
	*
	*	$restore  = 0;
	* $uprun    = 0;
	* $dataup   = 0;
	*
	*/
	
	//jumpTo(2,"../".$_SESSION["source_caller"]);
	
}else{
	
	$Misc->usrDieJs("Db connection failed");
}

?> 